package com.maikang.exammall.entity.dto.order;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.maikang.exammall.entity.OrderItem;
import com.maikang.exammall.entity.constant.OrderStatus;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Positive;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GroupedOrderItems {
    /**
     * group orderItem by pkgId
     */
    private String pkgAvatarUrl;
    @NotBlank
    private String pkgName;
    private Long pkgPrice;
    @Positive
    private Long pkgId;
    @ApiModelProperty("冗余， 评论订单的时候要带上")
    private Long orderId;
    @ApiModelProperty("该GroupedOrderItems是否可以评论")
    private boolean isCommentable;
    @ApiModelProperty("评论内容, 该字段用于创建评论")
    @NotBlank
    private String commentContent;
    private Integer pkgCount;
    private List<OrderItem> orderItems = new ArrayList<>();

    public GroupedOrderItems(OrderItem orderItem) {
        pkgAvatarUrl = orderItem.getPkgAvatarUrl();
        pkgName = orderItem.getPkgName();
        pkgPrice = orderItem.getPkgPrice();
        pkgId = orderItem.getPkgId();
        pkgCount = 0;
        orderId = orderItem.getOrderId();
        if (orderItem.getStatus().equals(OrderStatus.EXAMINED_TO_COMMENT)) {
            isCommentable = true;
        }
    }
}